package cn.initcap.controller;

import cn.initcap.common.Result;
import cn.initcap.rabbitmq.MqSender;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author initcap
 * @date Created in 2018/8/12 PM7:30.
 */
@RestController
public class MqController {
    private static final String SENDER_MESSAGE = "hello , initcap";
    private MqSender sender;

    @Autowired
    public MqController(MqSender sender) {
        this.sender = sender;
    }

    @RequestMapping("/mq")
    public Result mq() {
        sender.send(SENDER_MESSAGE);
        return Result.success();
    }

    @RequestMapping("/mq/topic")
    public Result topic() {
        sender.sendTopic(SENDER_MESSAGE);
        return Result.success();
    }

    @RequestMapping("/mq/fanout")
    public Result fanout() {
        sender.sendFanout(SENDER_MESSAGE);
        return Result.success();
    }

    @RequestMapping("/mq/header")
    public Result header() {
        sender.sendHeader("SENDER_MESSAGE");
        return Result.success();
    }

}
